<!-- 找回密码 -->
<template>
  <div class="wrap">
    <h2>找回密码</h2>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      class="demo-ruleForm"
    >
      <el-form-item prop="phone">
        <el-input v-model="ruleForm.phone" placeholder="请输入手机号码">
          <!-- <i slot="prefix" class="el-input__icon el-icon-search"></i> -->
          <i slot="prefix" class="iconi">
            <img :src="icon2" alt="" srcset="" />
          </i>
        </el-input>
      </el-form-item>
      <div class="sendcode">
        <el-form-item prop="code" class="codebox">
        <el-input v-model="ruleForm.code" placeholder="请输入验证码">
          <i slot="prefix" class="iconi">
            <img :src="icon2" alt="" srcset="" />
          </i>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="sendcode">发送验证码</el-button>
      </el-form-item>
      </div>

      <el-form-item prop="pwd">
        <el-input v-model="ruleForm.pwd" placeholder="请输入新密码">
          <!-- <i slot="prefix" class="el-input__icon el-icon-search"></i> -->
          <i slot="prefix" class="iconi">
            <img :src="icon3" alt="" srcset="" />
          </i>
        </el-input>
      </el-form-item>
      <el-form-item prop="dbPwd">
        <el-input v-model="ruleForm.dbPwd" placeholder="再次输入密码">
          <!-- <i slot="prefix" class="el-input__icon el-icon-search"></i> -->
          <i slot="prefix" class="iconi">
            <img :src="icon3" alt="" srcset="" />
          </i>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >确定</el-button
        >
      </el-form-item>
      <el-link :underline="false" class="tologinlink" @click="tologin"
        >已有账号，去登录</el-link
      >
    </el-form>
  </div>
</template>

<script>
var icon1 = require("../../../assect/loginimgs/main-icon-01.png");
var icon2 = require("../../../assect/loginimgs/main-icon-02.png");
var icon3 = require("../../../assect/loginimgs/main-icon-03.png");
export default {
  data() {
    var checkPhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("手机号不能为空"));
      }
      setTimeout(() => {
        callback();
      }, 200);
    };
    var checkPwd = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("密码不能为空"));
      }
      setTimeout(() => {
        callback();
      }, 200);
    };
    var checkCode = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("验证码不能为空"));
      }
      setTimeout(() => {
        callback();
      }, 200);
    };
    var checkDbPwd = (rule, value, callback) => {
      if (!this.ruleForm.pwd) {
        return callback(new Error("请先输入密码"));
      }
      if (!value) {
        return callback(new Error("请再次输入密码"));
      }
      if (this.ruleForm.pwd != value) {
        return callback(new Error("两次密码输入不一致"));
      }
      setTimeout(() => {
        callback();
      }, 200);
    };
    return {
      icon1,
      icon2,
      icon3,
      ruleForm: {
        phone: "",
        pwd: "",
        dbPwd: "",
        code:"",
      },
      rules: {
        phone: [{ validator: checkPhone, trigger: "blur" }],
        pwd: [{ validator: checkPwd, trigger: "blur" }],
        dbPwd: [{ validator: checkDbPwd, trigger: "blur" }],
        code:[{ validator: checkCode, trigger: "blur" }],
      },
    };
  },
  methods: {
    tologin() {
      this.$router.push("/login/login");
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message({
            message: "验证成功",
            type: "success",
          });
        } else {
          this.$message({
            message: "请输入正确的信息",
            type: "warning",
          });
          return false;
        }
      });
    },
  },
};
</script>
<style lang='less' scoped>
.sendcode{
  display:flex;align-items:center;justify-content: space-between;
  .el-button{
    height:48px;
    background-color: #666fe8;
    font-size:14px;
  }
  /deep/.el-input__inner {
    width:290px;
  }
}
.wrap {
  width: 600px;
  height: 725px;
  background-color: #fff;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  border-radius: 20px;
  text-align: center;
  box-sizing: border-box;
  padding: 120px 100px;
  h2 {
    font-weight: bold;
    font-size: 26px;
    text-align: left;
    margin-bottom: 35px;
  }
  .iconi {
    height: 48px;
    line-height: 44px;
    img {
      vertical-align: middle;
      margin-right: 5px;
    }
  }
  /deep/.el-input__inner {
    background: #f1f1fd;
    border-radius: 10px;
    border: 0;
    height: 48px;
    padding-left: 45px;
  }
  /deep/.el-form-item {
    margin-bottom: 24px;
  }
  /deep/.el-button:not(.sendcode) {
    width: 100%;
    height: 50px;
    margin-bottom: 15px;
    background-color: #666fe8;
    border: 0;
    border-radius: 8px;
  }
}
</style>